home *** CD-ROM | disk | FTP | other *** search
- Path: news.cloudnet.com!news
- From: "Randall J. Pfeifer" <rpfeifer@cloudnet.com>
- Newsgroups: comp.lang.c
- Subject: Nee help with a string and temp string
- Date: Wed, 10 Apr 1996 21:47:40 -0500
- Organization: Cloudnet, St. Cloud, MN
- Message-ID: <316C72CC.763A@cloudnet.com>
- NNTP-Posting-Host: pm184.cloudnet.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.01 (Win95; I)
-
- I am writing a program that reads data, validates it, and then writes it to a new file.
-
- My problem involves evaluating the second line. The program works like this.
-
- An 80 byte line is read from an ascii file. There can be many lines of data.
- Once a line is read, various components are evaulated.
- ie column 1 must always contain a "B".
- column 5-9 will contain a number padded with zeros from the left if necessary.
- ect.
-
- As each component is evaluated the result is concatenad to a buffer string, with the
- first component that is evaulated being copied instead of concatenaded.
- Once the whole line is evaulated and corrected if necessary, I write that line to a file.
-
- I then read another line and start the process over again.
-
- My problem involves lines 2 through X.
- Reading the data is fine. However, when I evaluate the components and write them to the
- buffer the previous lines data still resides in the string.
-
- How can I get rid of the old lines data in my temp string.
-
- I apologize for the length, but I have included a section of the code to help you understand
- my problem.
-
- Bcard is the temp string.
- line is the string that contains the line of data read from a file
- padright is a routine that pads numbers with zero.
-
- With one line of data this section works just fine. It only bombs on multile line of data
-
-
- I thank you in advance for any possible help.
-
- Randall Pfeifer
-
- void main();
- void examineAcard();
- void examineBcard();
- void examineCcard();
- void padright(char card[81], int start, int end, int size, int base);
- void readcard(char *card);
- void writecard();
- char Acard[81], Bcard[81], Ccard[81];
-
- int Counter = 0;
- char line[80];
-
- char *Space = " ";
-
- FILE *fpcardrd, *fpcardwrt;
-
- void main()
- { int count;
-
- readcard("BCARD");
- writecard();
-
- while ( fgets(line,80,fpcardrd) != NULL)
- {
- examineBcard();
- }
- fclose(fpcardwrt);
- }
-
- void examineBcard()
- { int result;
-
- strncpy(Bcard,"B",1);
- strncat(Bcard,&line[1],1);
- strncat(Bcard, Space,3);
-
- padright(Bcard,5,7,3,3);
- padright(Bcard,8,12,5,5);
- padright(Bcard,13,18,6,6);
- strncat(Bcard," ",1);
-
- padright(Bcard,20,22,3,3);
- padright(Bcard,23,27,5,5);
- padright(Bcard,28,33,6,6);
- strncat(Bcard," ",1);
-
- padright(Bcard,35,37,3,3);
- padright(Bcard,38,43,5,5);
- padright(Bcard,43,48,6,6);
- strncat(Bcard," ",1);
-
- padright(Bcard,50,52,3,3);
- padright(Bcard,53,57,5,5);
- padright(Bcard,58,63,6,6);
- strncat(Bcard," ",1);
-
- padright(Bcard,65,67,3,3);
- padright(Bcard,68,72,5,5);
- padright(Bcard,73,78,6,6);
- strncat(Bcard,"\n",1);
-
- fputs(Bcard,fpcardwrt);
-
- }
-